<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <style>
        .layui-form-label{width: 100px}
        .layui-input-block{margin-left: 130px}
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    选择车辆
                </label>
                <div class="layui-input-block">
                    <select name="car_id" lay-verify="required">
                        <option value="">请选择</option>
                        {foreach name="car" item="vo" key="key"}
                        <option value="{$vo['id']}">{$vo['car_number']} - {$car_type[$vo['car_type']]} - 可乘坐{$vo['passengers']}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    出发地
                </label>
                <div class="layui-input-block">
                    <input type="text" name="start_area" class="layui-input" lay-verify="required" autocomplete="off"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    目的地
                </label>
                <div class="layui-input-block">
                    <input type="text" name="end_area" class="layui-input" lay-verify="required" autocomplete="off"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    用车开始时间
                </label>
                <div class="layui-input-block">
                    <input type="text" name="start" id="start" class="layui-input" lay-verify="required" autocomplete="off"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    用车结束时间
                </label>
                <div class="layui-input-block">
                    <input type="text" name="end" id="end" class="layui-input" lay-verify="required" autocomplete="off"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    用车人数
                </label>
                <div class="layui-input-block">
                    <input type="number" name="people_num" class="layui-input" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    用车事由
                </label>
                <div class="layui-input-block">
                    <textarea name="reason" class="layui-input" style="height: 200px"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'jquery', 'uploads', 'laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        //建立编辑器
        laydate.render({
            elem: '#start'
            ,type: 'datetime'
            ,min: "{:date('Y-m-d H:i:s')}"
        });

        laydate.render({
            elem: '#end'
            ,type: 'datetime'
            ,min: "{:date('Y-m-d H:i:s')}"
        });

        form.on('submit(save)', function (data) {
            
            $.ajax({
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (res) {
                    //判断有没有权限
                    if (res && res.code == 999) {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 2000,
                        })
                        return false;
                    } else if (res.code == 0) {
                        layer.msg(res.msg,{icon:1,time:1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.reload();
                        });
                    } else {
                        layer.msg(res.msg,{icon:2,time:1500});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>